using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPRMulti.Tools
{
    public static class ExtendedByteArray
    {
        /// <summary>
        /// 返回byte数组的和
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static byte Sum1(this byte[] bytes, int start, int length)
        {
            byte sum = 0;
            int endIndex = start + length;

            if (bytes == null || bytes.Length < 1)
                new NullReferenceException("bytes is null or bytes length < 1");

            if (start > bytes.Length || endIndex > bytes.Length)
                new IndexOutOfRangeException("bytes Index OutOf Range");

            for (int i = start; i < endIndex; i++)
                sum += bytes[i];

            return sum;
        }
    }
}
